<template>
  <div>
    <nav-bar title="实名认证"/>
    <div class="content-box content_scroll" v-if="!userinfo.idcard">
      <h3>应国家相关法律，请进行实名认证：</h3>
      <p>1.根据国家未成年防沉迷政策要求，将限制未成年人每日游戏时间，充值等，详细请查看<span @click="$router.push('/anti_addiction')">《防沉迷政策》</span>；</p>
      <p>2.根据国家相关法律规定，游戏用户需进行实名认证。实名信息仅作认证不会泄露给他人。请如实填写信息。未实名认证将会影响正常游戏体验。</p>
      <input type="text" placeholder="请输入真实姓名" v-model="username">
      <input type="text" placeholder="请输入身份证号" v-model="idcard">
      <div class="submit" @click="sumbitClick">提交</div>
    </div>
    <div class="content-box content_scroll" v-else>
      <div class="username_box">
        <div class="username">
          <span>真实姓名</span>
          <span>{{userinfo.real_name}}</span>
        </div>
        <div class="idcard">
          <span>身份证号</span>
          <span>{{userinfo.idcard}}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {Toast} from 'vant'
import NavBar from '../../../../components/common/navbar/NavBar.vue'

export default {
  components: { NavBar },
  data() {
    return {
      username: '',
      idcard: '',
      userinfo: {}
    }
  },
  created () {
    this.getuserinfo()
  },
  methods: {
    getuserinfo() {
      this.axios.get("/userinfo.json", {}).then((res) => {
        this.userinfo = res.data.userinfo;
      });
    },
    sumbitClick() {
      var url = '/user_idcard_add'
      var data = {
        real_name: this.username,
        idcard: this.idcard,
        is_ajax: 1
      }
      getPost(url, data).then(res => {
        console.log(res);
        if(res.status == 'ok') {
          this.$store.commit('makeRealName',this.username)
          this.$store.commit('makeIdCard',this.idcard)
          this.username = ''
          this.idcard = ''
          this.$router.push('/userinfo')
        }else{
          this.username = ''
          this.idcard = ''
          Toast(res.info)
        }
      })
    }
  },
}
</script>

<style scoped>
.content-box h3 {
  font-size: .373333rem;
  color: #222222;
}
.content-box p {
  font-size: .32rem;
  color: #222222;
  line-height: .533333rem;
}

.content-box p span {
  color: #ff5543;
}

.content-box {
  box-sizing: border-box;
  padding: 0 .426667rem 0;
  background: #F2F2F2;
}

input {
  box-sizing: border-box;
  outline: none;
  width: 100%;
  height: 1.333333rem;
  border: 0;
  text-align: center;
  line-height: 1.333333rem;
  font-size: .32rem;
  color: #999999;
  background: #ffffff;
  border-radius: .213333rem;
  margin-top: .266667rem;
  margin-bottom: .266667rem;
}

.submit {
  margin-top: .533333rem;
  width: 100%;
  height: 1.173333rem;
  opacity: 1;
  background: #ff5543;
  border-radius: .133333rem;
  font-size: .373333rem;
  text-align: center;
  color: #ffffff;
  line-height: 1.173333rem;
}

.username_box {
  width: 100%;
  height: 2.666667rem;
  border-radius: .266667rem;
  background-color: #fff;
  margin-top: .4rem;
  font-size: .373333rem;
  color: #222;
}

.username,
.idcard {
  line-height: 1.333333rem;
}

.username_box span{
  margin-left: .266667rem;
}
</style>